<template>
	<view class="container"><yxylInputs :inputs="inputs" confirmText="添加" @confirm="confirm"></yxylInputs></view>
</template>

<script>
import yxylInputs from '@/components/yxyl-inputs/yxyl-inputs.vue';
export default {
	components: { yxylInputs },
	data() {
		return {
			inputs: [],
			communityId: ''
		};
	},
	onLoad(e) {
		// #ifdef H5
		this.$wechat.hideMenu();
		// #endif
		if (e.scene) {
			this.communityId = e.scene;
		} else {
			this.communityId = e.communityId;
		}
		this.inputs.push({ title: '手机号', key: 'telephone', placeholder: '请输入手机号', required: true, type: 'number', errMsg: '请输入名字' });
		this.inputs.push({ title: '真实姓名', key: 'userName', placeholder: '请输入真实姓名', required: true, type: 'text', errMsg: '请输入名字' });
		this.inputs.push({ title: '性别', key: 'sexuality', type: 'radio', range: [{ text: '男', value: '1' }, { text: '女', value: '2' }], default: '1' });
		this.inputs.push({ title: '生日', key: 'birthDay', type: 'date', default: '1919-01-01', startDate: '1919-01-01', endDate: '2019-01-01' });
	},
	methods: {
		confirm(e) {
			e.communityId = this.communityId;
			this.$http
				.request({
					url: 'api/Community/CreateCommunityStudentByAdmin',
					method: 'PUT',
					data: e
				})
				.then(() => {
					uni.showToast({
						icon: 'success',
						title: '添加成功',
						success() {
							setTimeout(function() {
								if (getCurrentPages().length > 1) {
									uni.navigateBack();
								} else {
									uni.redirectTo({
										url: '../list'
									});
								}
							}, 1500);
						}
					});
				});
		}
	}
};
</script>

<style lang="scss" scoped></style>
